package com.bsj.travel.def.common.DTO.tdengine;

import com.bsj.travel.constant.TdEngineDataConstants;
import com.bsj.travel.def.common.DTO.mqtt.EventAct;
import com.bsj.travel.def.monitor.tdengine.Fields;
import lombok.Data;

import java.util.List;

/**
 * @author yinhao
 * @version 1.0
 * @description 超级表子表的入参实体类
 * @date 2024/1/26
 */
@Data
public class TableDto {

    /**
     * 超级表名称/产品key
     */
    private String superTableName;
    /**
     * 子表名称/设备号
     */
    private String tableName;

    //TODO 内容。采用子表自动创建方式
    /**
     * 超级表普通列字段的值
     */
    private List<Fields> schemaFieldValues;
    /**
     * 超级表标签字段的值
     */
    private List<Fields> tagsFieldValues;

    public void transLogTableTs(String productKey, String deviceName, EventAct eventAct) {
        this.superTableName = TdEngineDataConstants.T_LOG + productKey;
        this.tableName = superTableName + "_" + deviceName;
        List<Fields> fieldsList = List.of(new Fields("ts", "timestamp", null, eventAct.getTimestamp()),
                new Fields("traceId", "string", 64, eventAct.getTraceId()),
                new Fields("serveType", "int", 2, eventAct.getServeType()),
                new Fields("operate", "string", 64, eventAct.getOperate()),
                new Fields("code", "int", 11, eventAct.getCode()));
        this.schemaFieldValues = fieldsList;
        List<Fields> tagFieldsList = List.of(new Fields("event", "string", 64, eventAct.getEvent().getEvent()));
        this.tagsFieldValues = tagFieldsList;
    }
}
